package cn.iocoder.yudao.module.book.controller.app.login;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.book.controller.app.login.vo.WeChatLoginRespVO;
import cn.iocoder.yudao.module.book.controller.app.login.voS.AppLoginRespVO;
import cn.iocoder.yudao.module.book.controller.app.login.voS.AppWeixinMiniAppLoginReqVO;
import cn.iocoder.yudao.module.book.service.WeChat.WeChatUserService;
import cn.iocoder.yudao.module.book.service.login.LoginService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import javax.annotation.Resource;
import javax.validation.Valid;

@Tag(name = "用户 APP - 认证")
@RestController
@RequestMapping("/login")
@Validated
public class AppLoginController {

    @Resource
    private LoginService authService;

    @Resource
    private WeChatUserService weChatUserService;
    @PostMapping("/weixin-mini-app-login")
    @Operation(summary = "微信小程序的一键登录")
    public CommonResult<AppLoginRespVO> weixinMiniAppLogin(@RequestBody @Valid AppWeixinMiniAppLoginReqVO reqVO) {
        return success(authService.weixinMiniAppLogin(reqVO));
    }

    @GetMapping("/applet/{code}")
    public CommonResult<WeChatLoginRespVO> loginByWeChatApplet(@PathVariable String code) {
        return CommonResult.success(weChatUserService.loginByWeChatApplet(code));

    }
}
